﻿using HCQ2_IBLL;
using HCQ2_Model;
using HCQ2_Model.ParamsModel;
using HCQ2_Model.ViewModel;
using HCQ2_Model.ViewModel.VR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HCQ2_BLL
{
    /// <summary>
    /// 订单相关    
    /// </summary>
    public partial class T_VROrderBLL: IT_VROrderBLL
    {
        /// <summary>
        /// 获取一个订单编号
        /// </summary>
        /// <returns></returns>
        public string GetOrderCode()
        {
            return DBSession.IT_VROrderDAL.GetOrderCode();
        }

        /// <summary>
        /// 获取订单列表
        /// </summary>
        /// <param name="orderListParams"></param>
        /// <returns></returns>
        public TableModel GetOrderList(OrderListParams orderListParams)
        {
            return DBSession.IT_VROrderDAL.GetOrderList(orderListParams);
        }

        /// <summary>
        /// 设置订单为付款状态
        /// </summary>
        /// <param name="orderCode">订单编码</param>
        /// <param name="pramoney">实际支付金额</param>
        public void Payment(string orderCode, decimal pramoney)
        {
            if (!string.IsNullOrEmpty(orderCode)) {
                T_VROrder order = new T_VROrder() {
                    order_code = orderCode,
                    pay_pramoney = pramoney,
                    handle_time = DateTime.Now,
                    status = 2
                };
                DBSession.IT_VROrderDAL.Modify(order,"pay_pramoney", "handle_time", "status");
            }
        }

        /// <summary>
        /// 取消订单
        /// </summary>
        /// <param name="orderCode">订单编码</param>
        public void Revoke(string orderCode)
        {
            if (!string.IsNullOrEmpty(orderCode))
            {
                T_VROrder order = new T_VROrder()
                {
                    order_code = orderCode,
                    handle_time = DateTime.Now,
                    status = 1
                };
                DBSession.IT_VROrderDAL.Modify(order,"handle_time", "status");
            }
        }

        /// <summary>
        /// 获取订单详细
        /// </summary>
        /// <param name="orderCode">订单编号</param>
        /// <returns></returns>
        public OrderDetailed GetOrderDetailed(string orderCode)
        {
            if (string.IsNullOrEmpty(orderCode)) {
                return null;
            }

            return DBSession.IT_VROrderDAL.GetOrderDetailed(orderCode);
        }
        /// <summary>
        ///  判断用户是否购买商品
        /// </summary>
        /// <param name="fileId"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public int GetShoppingFile(int fileId, int userId)
        {
            return DBSession.IT_VROrderDAL.GetShoppingFile(fileId, userId);
        }
        //********************************************接口************************************************
        /// <summary>
        ///  判断当前文件是否是被用户购买
        /// </summary>
        /// <param name="user_id">用户id</param>
        /// <param name="file_id">文件id</param>
        /// <returns></returns>
        public bool GetOrderResult(int user_id, int file_id)
        {
            int count = DBSession.IT_VROrderDAL.GetOrderResult(user_id, file_id);
            return count > 0 ? true : false;
        }
        /// <summary>
        ///  更新商品购买订单状态为：成功
        /// </summary>
        /// <param name="user_id"></param>
        /// <param name="file_id"></param>
        /// <returns></returns>
        public void ModifyOrderStatus(int user_id, int file_id)
        {
            DBSession.IT_VROrderDAL.ModifyOrderStatus(user_id, file_id);
        }
    }
}
